package com.eascs.admin.oldO2olike.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.admin.o2o.finance.entity.O2oFinanceFlowEntity;
import com.eascs.admin.o2o.finance.service.O2oFinanceFlowService;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.workflow.common.entity.wf.ProcessTemplate;


@RestController
@RequestMapping("/oldo2oliker")
public class Oldo2olikeRestController extends BaseRestController  {
	private static Logger logger = LoggerFactory.getLogger(Oldo2olikeRestController.class);

	@Autowired
	private O2oLoanapplyService o2oloanapplyService;
	@Autowired
	private  O2oFinanceFlowService financeFlowService;
	@Autowired
	private O2oLoanUserService o2oLoanUserService;

	@Value("${o2o.admin.agreeUrlShow}")
	private String agreeUrlShow;
	/**
	 * @Title: cwsh_detail
	 * @Description: 财务审核详情页面
	 * @author 张庆奇
	 * @param loanapplyNo
	 * @return
	 * @return BaseRestResult<String>
	 * @throws
	 * @date 2017年6月23日 上午9:56:22
	 */
	@RequestMapping("/cwsh_detail")
	public BaseRestResult<String>  cwsh_detail(String loanapplyNo) {
		logger.info("财务查询，贷款id：【{}】", loanapplyNo);
		O2oLoanapplyEntity o2oLoanapplyEntity = o2oloanapplyService.findById(loanapplyNo);
		O2oFinanceFlowEntity entity = financeFlowService.getByLoanApplyno(loanapplyNo);
		O2oLoanUserEntity loanUser = o2oLoanUserService.findById(o2oLoanapplyEntity.getLoanId(), o2oLoanapplyEntity.getLoanapplyNo());
		O2oLoanUserEntity loanSorpouseUser = o2oLoanUserService.findSpouseId(o2oLoanapplyEntity.getLoanId(), o2oLoanapplyEntity.getLoanapplyNo());
		ViewContext.put("loanapply", o2oLoanapplyEntity);
		ViewContext.put("entity", entity);
		ViewContext.put("loanUser", loanUser);
		ViewContext.put("loanSorpouseUser", loanSorpouseUser);
		String processType=ProcessTemplate.PROECESS_TYPE_FINANCE_AUDIT;
		String agreeUrl = agreeUrlShow+loanapplyNo+"&processType="+processType;
		ViewContext.put("agreeUrl", agreeUrl);
		return HtmlRestResult.popHtmlFragment("oldo2olike/cwsh/detail");
		
	}
	
	/**
	 * @Description:
	 *               <p>
	 *               面签申报提交时填写表单
	 *               </p>
	 * @author CXW
	 * @date 2017年8月16日 上午11:13:30
	 * @version V1.0
	 */
	@RequestMapping("/mq_bd")
	public BaseRestResult<String> mq_bd(String loanapplyNo){
		ViewContext.put("loanapplyNo", loanapplyNo);
		return HtmlRestResult.popHtmlFragment("oldo2olike/mqsb/mq_bd");
	}

}
